<?php

class orders{
	function getOrdersList(){
		$ordersList = array();
		qdbconn();
		
		$query = "select ord_id,ord_receivedate,em1.emp_name, ord_issuedate, em2.emp_name, 
					cus_firstname, pay_method,ord_status
					from orders o 
						join employees em1 on o.ord_empreceive_id = em1.emp_id
		     			join employees em2 on o.ord_empissue_id   = em2.emp_id
		      			join customers c   on o.ord_cus_id        = c.cus_id
		      			join payments p    on o.ord_pay_id 		  = p.pay_id";
		$result = mysql_query($query);
		
		$i = 0;
		while ($row = mysql_fetch_row($result)) {
			$ordersList[$i]['ord_id']			= $row[0];
			$ordersList[$i]['ord_receivedate']	= $row[1];
			$ordersList[$i]['emp_name']			= $row[2];
			$ordersList[$i]['ord_issuedate']	= $row[3];
			$ordersList[$i]['emp_name']			= $row[4];
			
			$ordersList[$i]['cus_firstname']	= $row[5];
			$ordersList[$i]['pay_method']		= $row[6];
			$ordersList[$i]['ord_status']		= $row[7];
			
			
			$i++;
		}
		return $ordersList;
	}
	
	function insertAOrder($data){
		qdbconn();
		$ord_receivedate	 = $data['ord_receivedate'];
		$ord_issuedate	 	 = $data['ord_issuedate'];
		
		$ord_empreceive_id	 = $data['ord_empreceive_id'];
		$ord_empissue_id	 = $data['ord_empissue_id'];
		
		$ord_cus_id	 		 = $data['ord_cus_id'];
		$ord_pay_id	 		 = $data['ord_pay_id'];

		$query = "INSERT INTO orders (ord_receivedate,ord_issuedate,ord_empreceive_id,
					ord_empissue_id,ord_cus_id,ord_pay_id) 
				values ('$ord_receivedate','$ord_issuedate',$ord_empreceive_id,
					$ord_empissue_id,$ord_cus_id,$ord_pay_id)";
				//echo $query; die;
		$result = mysql_query($query);
		return $result;
			
		}		
	
	
	function inactivateAOrder($ord_id){	
		qdbconn();		
		$query = "UPDATE orders SET ord_status = 0 where ord_id = $ord_id";
		$result = mysql_query($query);
		return $result;
	}
	
	function activateAOrder($ord_id){
		qdbconn();		
		$query = "UPDATE orders SET ord_status = 1 where ord_id = $ord_id";
		$result = mysql_query($query);
		return $result;
	}
	
	function editAOrder($data){
		qdbconn();
		$ord_id 			 = $data['ord_id'];
		$ord_receivedate	 = $data['ord_receivedate'];
		$ord_issuedate	 	 = $data['ord_issuedate'];
		
		$ord_empreceive_id	 = $data['ord_empreceive_id'];
		$ord_empissue_id	 = $data['ord_empissue_id'];
		
		$ord_cus_id	 		 = $data['ord_cus_id'];
		$ord_pay_id	 		 = $data['ord_pay_id'];		
		
		$query 		 = "UPDATE orders SET ord_receivedate='$ord_receivedate',
					ord_issuedate='$ord_issuedate', ord_empreceive_id=$ord_empreceive_id,
					ord_empissue_id=$ord_empissue_id,ord_cus_id = $ord_cus_id,
					ord_pay_id = $ord_pay_id WHERE ord_id = $ord_id";
          //echo $query;die;
		$result = mysql_query($query);
		return $result;
	}
	
	function getOrdersInfo($ord_id){
		qdbconn();		
		$query = "SELECT * FROM orders
					WHERE ord_id = $ord_id";
		$result = mysql_query($query);
		$current_data = array();
		if ($row = mysql_fetch_row($result)) {
			$current_data['ord_id'] 			= $row[0];
			$current_data['ord_receivedate'] 	= $row[1];
			$current_data['ord_issuedate'] 		= $row[2];
			$current_data['ord_empreceive_id'] 	= $row[3];
			$current_data['ord_empissue_id'] 	= $row[4];
			$current_data['ord_cus_id'] 		= $row[5];
			$current_data['ord_pay_id'] 		= $row[6];			
			$current_data['ord_status'] 		= $row[7];
		}
		return $current_data;
	
	}
}

?>